package com.example.nccdeploytool.util;

import java.util.Arrays;
import java.util.Optional;

public class OptionalUtils {

    @SafeVarargs
    public static <T> Optional<T> firstPresent(Optional<T>... optionals) {
        return Arrays.stream(optionals)
                .filter(Optional::isPresent)
                .findFirst()
                .orElse(Optional.empty());
    }

    @SafeVarargs
    public static <T> T firstPresentOrElse(T defaultValue, Optional<T>... optionals) {
        return Arrays.stream(optionals)
                .filter(Optional::isPresent)
                .map(Optional::get)
                .findFirst()
                .orElse(defaultValue);
    }
}
